package com.example.hello.client.Label;

import com.example.hello.BootstrapLabel;
import com.github.gwtbootstrap.client.ui.constants.LabelType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapLabel.class)
public class BootstrapLabelConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapLabel.class);
    }

    @Override
    public BootstrapLabelState getState() {
        return (BootstrapLabelState) super.getState();
    }

    @Override
    public VBootstrapLabel getWidget() {
        return (VBootstrapLabel) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapLabelState state = getState();

        VBootstrapLabel label = getWidget();

        label.setType(LabelType.valueOf(state.getType()));
        label.setText(state.getText());
    }

}